package com.liang.mapper;

import com.liang.pojo.User;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.support.SqlSessionDaoSupport;

import java.util.List;

public class UserMapperImpl extends SqlSessionDaoSupport implements UserMapper {

    //在原来，我们所有的操作，都使用sqlSeesion来执行；现在，都使用sqlSessionTemplate
    //private SqlSessionTemplate sqlSession;
    //
    //public void setSqlSession(SqlSessionTemplate sqlSession) {
    //    this.sqlSession = sqlSession;
    //}

    @Override
    public List<User> selectUser() {

        User user = new User(9, "spring3", "123123");

        UserMapper mapper = getSqlSession().getMapper(UserMapper.class);

        mapper.addUser(user);
        mapper.deleteUser(4);

        return mapper.selectUser();
    }

    @Override
    public int addUser(User user) {
        return getSqlSession().getMapper(UserMapper.class).addUser(user);
    }

    @Override
    public int deleteUser(int id) {
        return getSqlSession().getMapper(UserMapper.class).deleteUser(id);
    }
}
